package com.right.service.impl;

import java.util.List;

import com.Tools.PageData;
import com.right.dao.FoodsDao;
import com.right.dao.impl.FoodsDaoImpl;
import com.right.entity.Foods;
import com.right.service.FoodsService;

public class FoodsServiceImpl implements FoodsService {
	//创建一个成员变量foodsdao
	FoodsDao foodsDao = new FoodsDaoImpl();
	@Override
	public boolean addFoods(Foods foods) {
		// 增加菜品，先判断这个菜品是否存在；如果菜品已经存在，这不不执行添加操作；
		if (foods == null) {
			return false;
		}
		if (foodsDao.getOneFoods(foods.getFoodsname()) != null) {
			return false;
		}
		// 如果菜品不存在，再将这个菜品添加到数据库。
		boolean flag = foodsDao.addFoods(foods);
		return flag;
	}

	@Override
	public boolean delFoods(int foodsid) {
		// TODO Auto-generated method stub
		if (foodsid <=0) {
			return false;
		}
		boolean flag = foodsDao.delFoods(foodsid);
		return flag;
	}

	@Override
	public boolean updateFoods(Foods foods) {
		// TODO Auto-generated method stub
		if (foods ==null) {
			return false;
		}
		//判断有没有重复的菜品名
//		if (foodsDao.getFoodsByFoodsid(foods.getFoodsid()) != null) {
//				boolean flag = foodsDao.updateFoods(foods);
//				System.out.println(flag);
//				return flag;			
//		}
//		return false;
//		if(foodsDao.getOneFoods(foods.getFoodsname())!=null) {
//			return false;
//		}
		 return foodsDao.updateFoods(foods);
	}

	@Override
	public PageData<Foods> getFoodsPage(int page, int pageSize, String keywords) {
		// TODO Auto-generated method stub
		if (page < 1) {
			page = 1;
		}
		return foodsDao.getFoodsPage(page, pageSize, keywords);
	}

	@Override
	public Foods getOneFoods(String str) {
		// TODO Auto-generated method stub
		return foodsDao.getOneFoods(str);
	}

	
	@Override
	public List<Foods> getFoods(String keywords) {
		return foodsDao.getFoods(keywords);
	}
	
	@Override
	public Foods getFoodsByFoodsid(int foodsid) {
		
		return foodsDao.getFoodsByFoodsid(foodsid);
	}

}
